package com.example.yls.demoa;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    private Button button;
    private MyBroadcas receiver;
    private Button button1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

//        receiver=new MyBroadcas();
//        IntentFilter filter=new IntentFilter();
//        filter.addAction("weather_info");
//        filter.addAction("traffic_info");
//        registerReceiver(receiver,filter);

        button=findViewById(R.id.btn);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent();
                intent.setAction("weather_info");
                intent.putExtra("weather","晴天");
                intent.putExtra("wendu",25);
               sendBroadcast(intent);
            }
        });

        button1=findViewById(R.id.btn1);
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent();
                intent.setAction("traffic_info");
                intent.putExtra("traffic","堵车");
                intent.putExtra("time",2);

                sendBroadcast(intent);
            }
        });
    }
//  protected  void  onDestroy(){
//        unregisterReceiver(receiver);
//        super.onDestroy();
//  }

}
